<#include "common/layout.ftl"/>
<@layout "用户中心">
    <div class="layui-container fly-marginTop fly-user-main">
        <@centerLeft index=1></@centerLeft>

        <div class="site-tree-mobile layui-hide">
            <i class="layui-icon">&#xe602;</i>
        </div>
        <div class="site-mobile-shade"></div>

        <div class="site-tree-mobile layui-hide">
            <i class="layui-icon">&#xe602;</i>
        </div>
        <div class="site-mobile-shade"></div>

        <div class="fly-panel fly-panel-user" pad20>
            <!--
            <div class="fly-msg" style="margin-top: 15px;">
              您的邮箱尚未验证，这比较影响您的帐号安全，<a href="activate.html">立即去激活？</a>
            </div>
            -->
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title" id="LAY_mine">
                    <li data-type="mine-jie" lay-id="index" class="layui-this">我发的帖（<span>0</span>）</li>
                    <li data-type="collection" data-url="/collection/find/" lay-id="collection">我收藏的帖（<span>0</span>）
                    </li>
                </ul>
                <div class="layui-tab-content" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <ul class="mine-view jie-row" id="publish">
                        </ul>
                        <div id="LAY_page"></div>
                    </div>
                    <div class="layui-tab-item">
                        <ul class="mine-view jie-row" id="collection">
                        </ul>
                        <div id="LAY_page1"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script id="publishTpl" type="text/html">
        <li>
            <a class="jie-title" href="${basePath}/post/{{d.id}}" target="_blank">{{ d.title }}</a>
            <i>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}<</i>
            <a class="mine-edit" href="${basePath}/post/edit?id={{d.id}}">编辑</a>
            <em>{{d.viewCount}}阅/{{d.commentCount}}答</em>
        </li>
    </script>
    <script id="collectionTpl" type="text/html">
        <li>
            <a class="jie-title" href="${basePath}/post/{{d.id}}" target="_blank">{{ d.title }}</a>
            <i>收藏于{{layui.util.timeAgo(d.createTime, true)}}</i>
        </li>
    </script>
    <script type="text/javascript">
        layui.cache.page = 'user';
        layui.use(['laytpl', 'flow', 'util'], function () {
            var $ = layui.jquery;
            var laytpl = layui.laytpl;
            var flow = layui.flow;
            var util = layui.util;

            flow.load({
                elem: '#publish', //指定列表容器
                isAuto: false,
                done: function (page, next) {
                    var lis = [];

                    $.get('/user/publish?pn=' + page, function (res) {
                        layui.each(res.data.records, function (index, item) {
                            $("[lay-id='index'] span").text(res.data.total);

                            var tpl = $("#publishTpl").html();
                            laytpl(tpl).render(item, function (html) {
                                $("#publish .layui-flow-more").before(html);
                            });
                        });

                        next(lis.join(''), page < res.data.pages);
                    });
                }
            });

            flow.load({
                elem: '#collection',
                isAuto: false,
                done: function (page, next) {
                    var lis = [];

                    $.get('/user/collection?pn=' + page, function (res) {
                        layui.each(res.data.records, function (index, item) {
                            $("[lay-id='collection'] span").text(res.data.total);

                            var tpl = $("#collectionTpl").html();
                            laytpl(tpl).render(item, function (html) {
                                $("#collection .layui-flow-more").before(html);
                            });
                        });

                        next(lis.join(''), page < res.data.pages);
                    });
                }
            });
        });
    </script>
</@layout>